import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 存储token
    authorization: localStorage.getItem('authorization') ? localStorage.getItem('authorization') : '',
    userInfo: localStorage.getItem('uInfo') ? localStorage.getItem('uInfo') : '',
    isClickBtn: false
  },
  mutations: {
    // 修改token，并将token存入localStorage
    changeLogin(state, user) {
      state.authorization = user.authorization;
      localStorage.setItem('authorization', user.authorization);
    },
    // 修改userInfo，并将userInfo存入localStorage
    changeUserInfo(state, user) {
      state.userInfo = user.userInfo;
      localStorage.setItem('uInfo', user.userInfo);
    },
    isClickBtnF(state, bol) {
      state.isClickBtn = bol;
    }
  },
  actions: {
    isClickBtnF(context, bol) {
      context.commit("isClickBtnF", bol);
    }
  }
})
